package data

import (
	"fmt"
	"github.com/go-kratos/kratos/v2/log"
	"github.com/redis/go-redis/v9"
	"go-kratos-demo/internal/conf"
)

// Redis .\

// NewRedis .
func NewRedis(c *conf.Data, logger log.Logger) (*redis.Client, func(), error) {
	cleanup := func() {
		log.NewHelper(logger).Info("closing the data resources")
	}
	fmt.Println(c.Redis.Addr)
	rdb := redis.NewClient(&redis.Options{
		Addr:     c.Redis.Addr,
		Password: c.Redis.Password,
		DB:       int(c.Redis.Db),
	})
	return rdb, cleanup, nil
}
